package com.taotao.manage.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.constant.SystemConstant;
import com.taotao.common.dto.PageResult;
import com.taotao.common.dto.ResponseResult;
import com.taotao.common.dto.TreeNode;
import com.taotao.entity.Item;
import com.taotao.entity.ItemCat;
import com.taotao.manage.service.ItemCatService;
import com.taotao.manage.service.ItemService;

/**  
 * @Title：ItemController.java   
 * @Description：
 * @Author：张朝阳
 * @Date：2019年7月2日 下午10:48:18   
 */
@Controller
@RequestMapping("/item")
public class ItemController {

	@Autowired
	private ItemService itemService;
	
	@RequestMapping("/{itemId}")
	@ResponseBody
	public Item getItemById(@PathVariable Long itemId) {
		Item item = itemService.getItemById(itemId);
		return item;
	}
	
	@RequestMapping("/list")
	@ResponseBody
	public PageResult<Item> getItemList(int page ,int rows) {
		List<Item> itemList = itemService.getItemList(page, rows);
		PageResult<Item> result = new PageResult<>();
		result.setRows(itemList);
		result.setTotal(itemList.size());
		return result;
	}
	
	@RequestMapping(value="/save",method=RequestMethod.POST)
	@ResponseBody
	public ResponseResult saveItem(Item item ,String desc) {
		try {
			itemService.addItem(item, desc);
			return ResponseResult.ok();
		}catch (Exception e) {
			return ResponseResult.error(e.getMessage());
		}
	}
}
